/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-3-26 下午01:21:32
 */
package com.util;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 *
 */
public class ResultSetUtil {
	
	public static List<Map<String, String>> processRow(ResultSet rs) throws Exception {
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		int colCount = rs.getMetaData().getColumnCount();
		String colName = "";
		String rt = "";
		while (rs.next()) {
			HashMap<String, String> map = new HashMap<String, String>();
			for (int j = 1; j <= colCount; j++) {

				colName = rs.getMetaData().getColumnName(j).toLowerCase();
				if (rs.getMetaData().getColumnTypeName(j).equals("DATE")) {
					Date _d = rs.getDate(j) ;
					if (_d != null) {
						
						Calendar cal = Calendar.getInstance() ;
						cal.setTime(_d) ;
						
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
						rt = sdf.format(cal.getTime()) ;
					}else
						rt = "" ;
				}else
				{
					rt = rs.getString(j) ;
				}

				if (rt == null || "null".equals(rt))
					rt = "";

				map.put(colName, rt);
			}
			list.add(map);
		}
		return list;
	}

}
